import pygame
import threading

class Sound(threading.Thread):
    #Need to start pygame, so that we can play sounds
    def __init__(self):
        super(Sound,self).__init__()
        self.keyString = ""
        self.keyString2 = ""

    def setSound(self, string):
        self.keyString = string
        self.keyString2 = ""

    def setSound2(self, string):
        self.keyString2 = string

    def run(self):
        #See if the file exists.  If we get an error loading it, try loading a default sound
        #If there is no default sound, then report back.
        if(self.keyString != "" and self.keyString.endswith(" ") == False):
            try:
                sound = pygame.mixer.Sound("%s.wav" % self.keyString)
                sound.play()
            except pygame.error, message:
                try:
                    sound = pygame.mixer.Sound("default.wav")
                    sound.play()
                except pygame.error, message:
                    print "Cannot load sound1: %s.wav" % self.keyString    
    
        if(self.keyString2 != ""):
            try:
                sound = pygame.mixer.Sound("%s.wav" % self.keyString2)
                sound.play()
            except pygame.error, message:
                try:
                    sound = pygame.mixer.Sound("default.wav")
                    sound.play()
                except pygame.error, message:
                    print "Cannot load sound2: %s.wav" % self.keyString2
            
    def quit(self):        
        pygame.quit()


    